package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.User;
import com.itheima.reggie.dto.LoginDto;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class UserController {
    @Autowired
    UserService userService;


    @PostMapping("/user/sendMsg")
    public ResultInfo sendMsg(@RequestBody User user){
        userService.sendMsg(user.getPhone());
        return ResultInfo.success();
    }

    @PostMapping("/user/login")
    public ResultInfo login(@RequestBody LoginDto loginDto){
        String token = userService.login(loginDto.getPhone(),loginDto.getCode());
        return ResultInfo.success(token);
    }

    @PostMapping("/user/logout")
    public ResultInfo logout(){
        return ResultInfo.success();
    }
}
